<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>项目管理</title>
    <link rel="stylesheet" href="${base}/layui/css/layui.css">
    <style>
    	.layui-bg-black{        width: 200px;height: 136px;margin-right: 30px;float: left;text-align: center;font-size: 33px;color: #000000!important;padding-top: 30px;}
    	.hide {display: none;}
    	.checkbox{display: inline-block;}
    	.layui-form-item{font-size: 18px;}
    </style>
</head>
<body  class="layui-layout-body">
<#include "/common/left.flt">	
<div class="layui-main" style="position: absolute;left: 300px;top: 50px;" >
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>操作提示</legend>
</fieldset>
   
<blockquote class="layui-elem-quote layui-quote-nm">
 	<div class="layui-input-inline">
 		<button class="layui-btn" id="add" ><img alt="" src="${base}/images/addto.png" width="16px" height="16px" /> 新加</button>
 		<button class="layui-btn" id="del" ><img alt="" src="${base}/images/delete.png" width="16px" height="16px" /> 删除</button>
 		<button class="layui-btn" id="allot" ><img alt="" src="${base}/images/roles.png" width="16px" height="16px" /> 组成员</button>
 	</div>
</blockquote> 

<#list dataList as one>
     <div class="layui-bg-black" style="background: url('${base}/images/computer.png') no-repeat;" ondblclick="show('${one.id}','${one.name}')"><input type="checkbox" name="id" value="${one.id}" groupids="${one.groupids}" cname="${one.name}" />${one.name}</div>
</#list>
</div>
<form action="${base}/util/uploadFile" method="post" name="uploadForm" enctype="multipart/form-data" id="uploadForm" class="hide" >
    <input name="pic" type="file" id="pic" class="hide"/>
</form>
</body>
<script src="${base}/js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="${base}/layui/layui.all.js"></script>
<script type="text/javascript">


$("#allot").click(function(){
	var groupids = "";
	var i = 0;
	var id = 0;
	var name = "";
	$("input[name='id']").each(function(){
		if ($(this).is(':checked')){
			groupids = $(this).attr("groupids");
			name = $(this).attr("cname");
			id = $(this).attr("value");
			i = i + 1;
		}
	});
	if (i == 0 ){
		layer.msg("没有选择记录！");
	} else if (i == 1) {
		layer.open({
			title: name +'配置成员' 
		    ,type: 1
		    ,id: 'layer1' //防止重复弹出
		    ,area:['400px', '260px']
		    ,content: '<#list userList as one><div class="layui-form-item"><div class="layui-input-block"><input class="checkbox" type="checkbox" value="${one.account}" name="user-${one.account}" title="${one.name}">${one.name}</div></div></#list>'
		    ,btn: '确定'
		    ,btnAlign: 'c' //按钮居中
		    ,shade: 0 //不显示遮罩
		    ,yes: function(){
		    	var values = "";
		    	var k = 0;
		    	$("input.checkbox").each(function(){
		    		if ($(this).is(':checked')){
		    			values = values + $(this).attr("value") +"-t,";
		    			k = k + 1;
		    		}
		    	});
		    	console.log(k);
		    	console.log(values);
		    	$.post("${base}/index/projectUserUpdate",
		        		{"id":id, "groupids":values},function(data){ 
		        			layer.alert(data);
		        			window.location.reload();
		        		}
		        );
		    }
		});	
		console.log("groupids:"+groupids);
		var groupidsArray = groupids.split(",")
		for(var j = 0 ; j < groupidsArray.length ; j++) {
			console.log(groupidsArray[j]);
			$("input[name=user-"+groupidsArray[j].replace("-t","")+"]").attr("checked","checked");	
		}
		
	} else {
		layer.msg("只选择一个查看！");
	}
});
$("#add").click(function(){
	layer.open({
	    type: 1
	    ,title:'新建项目'
	    ,id: 'layer1' //防止重复弹出
	    ,area:['400px', '260px']
	    ,content: '<div class="layui-input-inline" style="margin-top: 60px;"><label class="layui-form-label">项目名</label><input type="text" name="name" id="name"  placeholder="请输入项目名"  class="layui-input" style="width: 200px;"></div>'
	    ,btn: '确定'
	    ,btnAlign: 'c' //按钮居中
	    ,shade: 0 //不显示遮罩
	    ,yes: function(){
	    	var name = $("#name").val();
	        $.post("${base}/index/projectAdd",
	        		{"name":name},function(data){ 
	        			layer.alert(data);
	        			window.location.reload();
	        		}
	        );
	    }
	});
});

function show(id,name) {
	layer.open({
	    type: 1
	    ,id: 'layer1' //防止重复弹出
	    ,area:['400px', '260px']
	    ,content: '<div class="layui-input-inline" style="margin-top: 60px;"><label class="layui-form-label">项目名</label><input type="text" name="name" id="name"  placeholder="请输入项目名" value=\"'+name+'" class="layui-input" style="width: 200px;"></div>'
	    ,btn: '确定'
	    ,btnAlign: 'c' //按钮居中
	    ,shade: 0 //不显示遮罩
	    ,yes: function(){
	    	var name = $("#name").val();
	        $.post("${base}/index/projectUpdate",
	        		{"id":id,"name":name},function(data){ 
	        			layer.alert(data);
	        			window.location.reload();
	        		}
	        );
	    }
	});
}

$("#del").click(function (){
	var values = "";
	var i = 0;
	$("input[name='id']").each(function(){
		if ($(this).is(':checked')){
			values = values + $(this).attr("value") +",";
			i = i + 1;
		}
	});
	if (i > 0){
		$.post("${base}/index/projectDel",
        		{"ids":values},function(data){ 
        			layer.alert(data);
        			window.location.reload();
        		}
        );
	} else {
		layer.msg("没有选择记录！");
	}
});
</script>
</html>